package com.cicigodd.brick.plug.weixin.map.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * @author cicigodd
 * @date 2022-11-16 9:11
 */
@Configuration
public class WxMapConfig {

    @Resource
    private WxMapProperties wxMapProperties;


    @Bean
    public WxMpService wxMpService() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(wxMapProperties.getAppId());
        wxMpDefaultConfig.setSecret(wxMapProperties.getSecret());
        wxMpDefaultConfig.setOauth2redirectUri(wxMapProperties.getRedirectUrl());
        WxMpService service = new WxMpServiceImpl();
        service.setWxMpConfigStorage(wxMpDefaultConfig);
        return service;
    }

}
